package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportUserCardLog;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportUserCardLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2019-07-06 10:59:02
 */
public class TransportUserCardLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportUserCardLogConverts.class);

    public static List<TransportUserCardLogDTO> convert(List<TransportUserCardLog> transportUserCardLogList) {
        if (CollectionUtils.isEmpty(transportUserCardLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportUserCardLogDTO> transportUserCardLogListResult = Lists.newArrayList();
        for (TransportUserCardLog transportUserCardLog : transportUserCardLogList) {
            transportUserCardLogListResult.add(convert(transportUserCardLog));
        }
        return transportUserCardLogListResult;
    }

    public static TransportUserCardLogDTO convert(TransportUserCardLog transportUserCardLog) {
        try {
            return BeanUtils.copy(transportUserCardLog, TransportUserCardLogDTO.class);
        } catch (Exception e) {
            LOG.error("TransportUserCardLog到TransportUserCardLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportUserCardLog到TransportUserCardLogDTO转换失败", e);
        }
    }

    public static TransportUserCardLog convert(TransportUserCardLogDTO transportUserCardLogDTO) {
        try {
            return BeanUtils.copy(transportUserCardLogDTO, TransportUserCardLog.class);
        } catch (Exception e) {
            LOG.error("TransportUserCardLogDTO到TransportUserCardLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportUserCardLogDTO到TransportUserCardLog转换失败", e);
        }
    }
}